home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / hpglvu10.zip / HPGLVIEW.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-18  |  33KB  |  999 lines

  1. program HPGLVIEW;
  2. {-----------------------------------------------------------------------------}
  3.  (*                          An HPGL viewer
  4.  
  5.     The viewer takes a file of HPGL commands and displays the plot commands
  6.     on the screen.
  7.  
  8.     It always represents the page (A3 or A4) lying sideways on the
  9.     screen, to preserve the maximum resolution, and ignores the aspect ratio
  10.     of the screen for the same reason.
  11.  
  12.     Its designed to show you what the plot looks like on the page not be
  13.     an absolute mimic of a plot.  If you need absolute precision, plot it.
  14.  
  15. -------------------------------------------------------------------------------
  16.             HPGLVIEW - a on-screen Previewer for HPGL files
  17.     
  18.                 Copyright (C) 1991 Giovanni S. Moretti
  19.  
  20.     This program is free software; you can redistribute it and/or modify
  21.     it under the terms of the GNU General Public License as published by
  22.     the Free Software Foundation; either version 1, or (at your option)
  23.     any later version.
  24.  
  25.     This program is distributed in the hope that it will be useful,
  26.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  27.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  28.     GNU General Public License for more details.
  29.  
  30.     You should have received a copy of the GNU General Public License
  31.     along with this program; if not, write to the Free Software
  32.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  33.  
  34. -----------------------------------------------------------------------------
  35.     Giovanni Moretti                    | EMAIL:  G.Moretti@massey.ac.nz
  36.     Computer Centre,  Massey University |  
  37.     Palmerston North, New Zealand       |
  38. -----------------------------------------------------------------------------
  39.  
  40.    Please send me a copy of any major hacks/improvements so I can coordinate
  41.    any new releases.
  42.  
  43.    HP-GL is (probably) a trademark of Hewlett-Packard Company.
  44.  
  45. *)
  46. {-----------------------------------------------------------------------------}
  47. { RCS Control Information
  48.   $Author: Giovanni_Moretti $
  49.   $Date: 91/04/18 15:57:59 $
  50.   $Revision: 1.1 $
  51.   $Log:    hpglview.pas $
  52. Revision 1.1  91/04/18  15:57:59  ROOT_DOS
  53. Initial revision
  54.  
  55. uses graph, dos, crt, smalfont, { Like FONTS.PAS with only SMALLFONT left}
  56.      drivers;
  57.  
  58. const A3_char_width  = 0.285; {cm}
  59.       A3_char_height = 0.375;
  60.  
  61.       A4_char_width  = 0.187;
  62.       A4_char_height = 0.269;
  63.  
  64.       unknown_max    = 100;
  65.  
  66. var pen_down     : boolean;
  67.     cmd          : string;          {Current HPGL command being done}
  68.     x, y, x1,y1  : real;            {and the numeric arguments to this cmd}
  69.     lbl          : string;          {or a character string arg for LB cmd }
  70.  
  71.     filename     : string;
  72.     inf          : text;            {Input file}
  73.  
  74.     screen_max_X : integer;         {No of dots across screen -1}
  75.     screen_max_Y : integer;         {and number down            }
  76.  
  77.     Graphics_Driver  : integer;     { for BGI - may be set manually with /G }
  78.     Graphics_mode    : integer;     { for BGI - may be set manually with /G }
  79. {-----------------------------------------------------------------------------}
  80.     use_plotter_units : boolean;    {If TRUE => NO Scaling, FALSE => Scale}
  81.  
  82.     x_max        : real;            {Maximum and Minimum values as defined}
  83.     x_min        : real;            {by the SC (Scale) command            }
  84.     y_max        : real;
  85.     y_min        : real;
  86.  
  87.     x_p1, y_p1   : integer;
  88.     x_p2, y_p2   : integer;
  89. {-----------------------------------------------------------------------------}
  90.     Paper_size     : integer;         {Either a 3 or 4 (A3 or A4) }
  91.     X_plot_area_mm : integer;
  92.     Y_plot_area_mm : integer;
  93.     args           : boolean;
  94.     hard_clip_X    : integer;
  95.     hard_clip_Y    : integer;
  96.  
  97.     colour         : integer;         {Current colour from video palette}
  98. {-----------------------------------------------------------------------------}
  99.     char_height    : real;         {Currently set Character Height and Width}
  100.     char_width     : real;         {Always defined - used by SI and DI cmds }
  101.  
  102.     text_direction : word;         {Used by DI cmd }
  103. {-----------------------------------------------------------------------------}
  104.     symbol_mode    : boolean;      {Whether a symbol is drawn on a PA or PR }
  105.     symbol_char    : char;         {command - used by the SM instruction    }
  106. {-----------------------------------------------------------------------------}
  107.     {Remember unimplemented commands in this array for later }
  108.  
  109.     unknown_cmds   : array [1..unknown_max] of string;
  110.     unknown_count  : integer;
  111.  
  112.     cnt          : integer;
  113.     pause        : char;
  114.  
  115.     ch           : char;
  116.     debug        : boolean;
  117.     digits       : set of char;
  118.     i            : integer;      {General Purpose Integer}
  119.     finished     : boolean;
  120.  
  121.     initialise_cmd_count : integer;  {Used to pause on 2nd, 3rd ... IN cmd}
  122.     IP_cmd_count         : integer;  {Used to change colours on 2nd .. IP cmd}
  123.     auto_detect_graphics : boolean;  {altered be /G command line option }
  124. {-----------------------------------------------------------------------------}
  125.  
  126. procedure SET_DEFAULT_TEXT_DIRECTION;
  127. begin
  128.   text_Direction:= HorizDir;
  129.   SetTextJustify(LeftText,  BottomText);
  130. end;
  131.  
  132. {-----------------------------------------------------------------------------}
  133. { Set up the appropriate scaling factors to draw text of the size defined by
  134.   HEIGHT and WIDTH.
  135.  
  136.   HEIGHT and WIDTH are remembered in CHAR_HEIGHT and CHAR_WIDTH so
  137.   this procedure  can be reused if TEXT_DIRECTION is redefined.
  138.  
  139.   This procedure is used whenever it is necessary to change either
  140.   text size or direction.
  141. }
  142.  
  143. procedure SET_TEXT_SIZE (width, height : real); {Arguments are in Centimetres}
  144.  
  145. var x_top, x_bottom, y_top, y_bottom : integer;
  146.     width_in_mm, height_in_mm        : real;
  147.     scale_x, scale_y                 : real;
  148.     letter_height, letter_width      : integer;
  149.  
  150. begin
  151.       {Scale ratios by 100 so as not to lose too much precision on ROUND()}
  152.       x_top:= 100; x_bottom:= 100; y_top:= 100; y_bottom:= 100;
  153.  
  154.       {This Section Gives "Approximately" the correct size lettering }
  155.       SetTextStyle(SmallFont, HorizDir, 2);
  156.       letter_height:= TextHeight('M');     {Remember Size of Standard Characters}
  157.       letter_width := TextWidth('M');
  158.  
  159.       width_in_mm := letter_width / screen_max_X * X_plot_area_mm;
  160.       scale_x:= (width*10) / width_in_mm;     { *10 as SI args are in cm}
  161.       if scale_x > 10 then scale_x:= 10;
  162.       if scale_X > 1 then x_top   := round(scale_x   *100)
  163.       else                x_bottom:= round(1/scale_X *100);
  164.  
  165.       height_in_mm:= Letter_Height / screen_max_Y * Y_plot_area_mm;
  166.       scale_y:= (height*10) / height_in_mm;   { *10 as SI args are in cm}
  167.       if scale_y > 10 then scale_y:= 10;
  168.       if scale_y > 1 then Y_top   := round(scale_Y   *100)
  169.       else                Y_bottom:= round(1/scale_Y *100);
  170.  
  171.       SetUserCharSize(x_top, x_bottom, y_top, y_bottom);
  172.       SetTextStyle(smallFont, text_direction, UserCharSize);
  173. end;
  174.  
  175. {-----------------------------------------------------------------------------}
  176.  
  177. procedure SET_DEFAULT_TEXT_SIZE;
  178. begin
  179.   if paper_size = 4 then      { A4 Paper }
  180.     begin
  181.       char_height   := A4_char_height;
  182.       char_width    := A4_char_width;
  183.     end
  184.   else                        { A3 Paper }
  185.     begin
  186.       char_width    := A3_char_width;
  187.       char_height   := A3_char_height;
  188.     end;
  189.   set_text_size(char_width, char_height);
  190. end;
  191. {-----------------------------------------------------------------------------}
  192.  
  193. procedure SET_P1_P2 (x, y, x1, y1 : integer);
  194. begin
  195.   x_p1:= x;
  196.   y_p1:= y;
  197.   x_p2:= x1;
  198.   y_p2:= y1;
  199. end;
  200. {-----------------------------------------------------------------------------}
  201.  
  202. procedure SET_DEFAULT_P1_P2;
  203. begin
  204.   if paper_size = 4 then     { A4 Paper }
  205.     begin
  206.       x_p2          := 10430;
  207.       x_p1          :=   430;
  208.       y_p2          :=  7400;
  209.       y_p1          :=   20